<template>
	<view style="height:auto!important;">
		<view class="cf-container ns-border-color-gray">
			<view class="tab">
				<view @click="selected('promoter')"><text
						:class="type == 'promoter' ? 'ns-text-color active' : ''">推广员</text></view>
				<!-- <view @click="selected('member')"><text
						:class="type == 'member' ? 'ns-text-color active' : ''">会员</text></view> -->
			</view>
		</view>
		
		<view class="category-search-box" >
			<text class="iconsearch_light iconfont category-search-btn" @click="search()"></text>
			<input class="uni-input" type="text" maxlength="50"  v-model="searchText" confirm-type="搜索" placeholder="请输入关键词" @confirm="search()" />
		</view>

		<view class="item" v-for="(item, index) in list" :key="index" >
			<image :src="item.user_headimg ? $util.img(item.user_headimg) : $util.img('upload/uniapp/default_head.png')"
				mode="aspectFill" />
			<view class="info" @click="myclick(item.uid,item.jibie)">
				<view class="" style="display: flex; flex-wrap: wrap;">
					<view class="" style="display: flex;">
						<view class="" style="margin-bottom: 5rpx;">{{ item.nick_name }} </view>
						<view style="margin-left: 50rpx;color: red;font-size: 16rpx;margin-top: 5rpx;font-weight: bold;" v-if="item.jibie==0?item.sums:(item.jibie==1?item.psums:item.ppsums)" >新进{{item.jibie==0?item.sums:(item.jibie==1?item.psums:item.ppsums)}}笔订单</view>
						<!-- <view class="role-name" v-if="item.is_partner == 1">股东</view> -->
						<!-- <view class="role-name" v-else-if="item.is_promoter == 1">推广员</view> -->
						<!-- <view class="role-name" v-else>会员</view> -->
					</view>
					<view class="role-user ns-text-color-gray" v-if="item.recommender_name">
						推荐人：{{ item.recommender_name }}</view>
				</view>
				<view class="">
					{{item.city}}
				</view>
				<view class="time ns-text-color-gray">注册时间：{{ $util.timeStampTurnTime(item.reg_time) }}</view>
			</view>
			<image src="../../static/images/ditu.png" style="width: 60rpx;height: 60rpx;" @tap="goLocation(item)">
			</image>
		</view>

		<uni-load-more :status="status" :content-text="contentText" v-if="list.length > 0 && pageCount > 1" />
		<!-- 数据为空 -->
		<view v-if="isEmpty && list.length == 0" class="empty">
			<view class="ns-text-color-gray ns-font-size-base">您当前还没有团队哦</view>
		</view>
		<ns-login ref="login" href="distribution"></ns-login>
	</view>
</template>

<script>
	import http from 'common/js/http.js';
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	import nsLogin from 'components/ns-login/ns-login.vue';
	export default {
		components: {
			uniLoadMore,
			nsLogin
		},
		data() {
			return {
				searchText:"",
				type: 'promoter',
				promoterId: 0,
				pageIndex: 1,
				pageCount: 0,
				list: [],
				Scroll:0,
				isEmpty: false,
				status: 'loading',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多了'
				},
				ident: false //防止初始化时，触发上拉加载
			};
		},
		mixins: [http],
		onLoad(data) {
			console.log("11111111111111111")
			this.promoterId = data.promoter_id || 0;
			this.selected('promoter');

		},
		
		onPageScroll(e) {
			this.Scroll=e.scrollTop
			uni.setStorageSync('scrollTopIndex', this.Scroll)
		},

		onShow() {
			console.log("222222222222222")
				var scrollTopIndexIndex=uni.getStorageSync('scrollTopIndex')
			var timer = setTimeout(() => {
				console.log("scrollTopIndexIndex=================",scrollTopIndexIndex)
				uni.pageScrollTo({
					duration: 0, //过渡时间必须为0，uniapp bug，否则运行到手机会报错
					scrollTop: scrollTopIndexIndex, //滚动到目标位置
					success: function() {}
				})
				clearTimeout(timer)
			}, 100)
			
			var isLogin = false;
			// #ifdef H5
			getApp().checkLogin(() => {
				isLogin = true;
				setTimeout(() => {
					this.$refs.login.clickLogin();
				}, 100);
			});
			// #endif
			// #ifdef MP
			getApp().$vm.checkLogin(() => {
				isLogin = true;
				this.$refs.login.clickLogin();
			});
			// #endif

			if (isLogin) return;





		},
		methods: {
			search(){
				this.getTeamList('refresh');
			},
			myclick(e,jibie) {
				uni.navigateTo({
					url: '/pages/team-list/list?e=' + e+'&jibie='+jibie
				})

			},

			goLocation(e) {
				console.log('1111111=========', e)
				uni.openLocation({
					// latitude:parseFloat(e.latitude), //经纬度
					// longitude:parseFloat(e.longitude), //纬度
					latitude: parseFloat(e.lat), //经纬度
					longitude: parseFloat(e.long), //纬度
					name: e.name, //当前坐标名称
					scale: 15, //缩放比例
					address: e.name //目的地名称
				})
				

				// uni.getLocation({
				// 	type: 'gcj02', //返回可以用于uni.openLocation的经纬度
				// 	success: function(res) {
				// 		uni.openLocation({
				// 			latitude: parseFloat(e.latitude), //经纬度
				// 			longitude: parseFloat(e.longitude), //纬度
				// 			name: e.name, //当前坐标名称
				// 			scale: 15, //缩放比例
				// 			address: e.name //目的地名称
				// 		})
				// 	}
				// });
			},
			selected(type) {
				this.pageIndex = 1;
				this.status = 'loading';
				this.type = type;
				this.list = [];
				this.getTeamList('refresh');
			},
			getTeamList(type = 'refresh') {
				var datas={promoter_id: this.promoterId,page: this.pageIndex,type: this.type}
				if(this.searchText){
					datas.searchText=this.searchText
				}
				this.sendRequest({
					url: 'System.Distribution.myTeam',
					data: datas,
					success: res => {
						if (res.code == 0) {
							console.log("res===========================",res.data)
							let data = res.data;
							console.log("data==========================",data)
							this.pageCount = res.data.page_count;
							if (this.pageCount == 0) {
								this.status = 'nomore';
								this.isEmpty = true;
								this.contentText.contentnomore = '';
							} else {
								if (this.pageIndex < this.pageCount) {
									this.status = 'more';
								} else {
									this.status = 'nomore';
									this.contentText.contentnomore = '没有更多了';
								}
								this.isEmpty = false;

								if (data.length > 0) {
									if (type == 'refresh') {
										console.log("进来了=====================")
										this.list = data;
									} else {
										console.log("2222222222222=====================")
										this.list = this.list.concat(data);
									}
									this.pageIndex++;
								}else{
									this.list=[]
								}
							}
						}
					}
				});
			},
			clickLogin() {
				this.$refs.login.clickLogin();
			},
			onReachBottom() {
				if (!this.ident) return;
				this.getTeamList();
			}
		}
	};
</script>

<style lang="scss">
	.category-search-box {
		overflow: hidden;
		position: relative;
		height: 120rpx;
		.category-search-btn {
			position: absolute;
			z-index: 5;
			right: 60rpx;
			top: 50%;
			transform: translateY(-50%);
			font-size: $ns-font-size-lg + 4rpx;
		}
		input {
			height: 70rpx;
			width: 80%;
			display: block;
			background-color: #fff;
			border-radius: 6rpx;
			padding: 0 30rpx;
			margin: auto;
			font-size: $ns-font-size-base;
			margin-top: 24rpx;
		}
	}
	.cf-container {
		max-width: 1280rpx;
		background: #fff;
		overflow: hidden;
		border-bottom: 2rpx solid;
		margin-bottom: 20rpx;
	}

	.tab {
		display: flex;
		justify-content: space-between;
	}

	.tab>view {
		text-align: center;
		flex: 1;

		text {
			display: inline-block;
			line-height: 88rpx;
		}
	}

	.active {
		border-bottom: 4rpx solid $base-color;
	}

	.item {
		padding: 30rpx;
		margin-bottom: 30rpx;
		background: #fff;
		display: flex;
		justify-content: flex-start;
		align-items: center;

		image {
			width: 100rpx;
			height: 100rpx;
		}

		.info {
			flex: 1;
			width: calc(100vw - 180rpx);
			margin-left: 20rpx;

			.nack-info {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: center;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;

				.name-wrap {
					display: flex;
					max-width: 65%;

					.nick-name {
						max-width: 50%;
						overflow: hidden;
						white-space: nowrap;
						text-overflow: ellipsis;
					}

					.role-name {
						padding: 0 20rpx;
						line-height: 50rpx;
						border-radius: 25rpx;
						background: $base-color;
						margin-left: 30rpx;
						color: #ffffff;
						display: inline-block;
					}
				}

				.role-user {
					max-width: 35%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: $ns-font-size-sm;
				}
			}

			.time {}
		}
	}
</style>
